<?php

namespace app\admin\controller\train;

use app\admin\model\train\Article as M;
use app\common\controller\Backend;

class Article extends Backend
{
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new M;
        $this->view->assign("statusList", $this->model->getStatusList());
    }

    public function index()
    {
        $this->request->filter(['strip_tags', 'trim']);
        if (!$this->request->isAjax()) {
            return $this->fetch();
        }
        if ($this->request->request('keyField')) {
            return $this->selectpage();
        }
        list($where, $sort, $order, $offset, $limit) = $this->buildparams();
        $list = $this->model->where($where)->order($sort, $order)->paginate($limit);
        return json([
            "total" => $list->total(),
            "rows"  => $list->items(),
        ]);
    }
}
